﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DTO;
using System.Data.SqlClient;

namespace DAO
{
    public class PhuThuDAO
    {
        public class SqlConnectionData
        {
            public static SqlConnection Connection()
            {
                SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=QLKSAN;Integrated Security=True");
                return conn;
            }
        }

        public static DataTable GetAll()
        {
            SqlConnection conn = SqlConnectionData.Connection();
            SqlCommand cmd = new SqlCommand("sp_PhuThuGetAll", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            return dt;
           
        }

        public static void InsertPhuThu(PhuThuDTO pt)
        {
            SqlConnection conn = SqlConnectionData.Connection();
            SqlCommand cmd = new SqlCommand("sp_InsertPhuThu", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@SoThuTu", SqlDbType.Int);
            cmd.Parameters.Add("@TyLePhuThu", SqlDbType.Float);
            cmd.Parameters["@SoThuTu"].Value = pt.SoThuTu;
            cmd.Parameters["@TyLePhuThu"].Value = pt.TyLePhuThu;
            conn.Open();
            cmd.ExecuteNonQuery();
            conn.Close();
        }
        public static void UpdatePhuThu(PhuThuDTO pt)
        {
            SqlConnection conn = SqlConnectionData.Connection();
            SqlCommand cmd = new SqlCommand("sp_UpdatePhuThu", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@MaPhuThu", SqlDbType.Int);
            cmd.Parameters.Add("@SoThuTu", SqlDbType.Int);
            cmd.Parameters.Add("@TyLePhuThu", SqlDbType.Float);
            cmd.Parameters["@MaPhuThu"].Value = pt.MaPhuThu;
            cmd.Parameters["@SoThuTu"].Value = pt.SoThuTu;
            cmd.Parameters["@TyLePhuThu"].Value = pt.TyLePhuThu;
            conn.Open();
            cmd.ExecuteNonQuery();
            conn.Close();
        }
        public static DataTable LayTyLePhuThu(int sothutu)
        {
            string sql = "Select * From PHUTHU Where SoThuTu = " + sothutu + "";
            DataTable dt = DataProvider.ExecuteQuery(sql);
            return dt;
        }
    }
}
